package com.k2data.k2app.service.pas04;

import com.k2data.k2app.domain.vo.Job;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 预警处理
 * Created by clb on 17-4-18.
 */
@Log4j2
@Service
public class Job04Service {
	@Autowired
	private Pas04JobService pasJobService;
	@Autowired
	private Pas04JobService pas04JobService;
	@Autowired
	private Pas04ResultService pas04ResultService;

	/**
	 *  获取单个job
	 * @return
	 */
	@Transactional
	public Job  get (Long jobId) throws Exception {
		if(jobId == null){
			return null;
		}
		Map<String,String> param = new HashMap<>(16);
		param.put("id",jobId+"");
		List<Job> jobs = listJobs(param);
		if(jobs.size()>0){
			return jobs.get(0);
		}
		return  null;
	}

	/**
	 * 查询项目相关的所有jobs
	 */
	@Transactional
	public List<Job> listJobs(Map params) throws Exception{
		List<Job> list = pas04JobService.getJobsByParam(pas04JobService.getQueryCondition(params));
		return list;
	}


	/**
	 * 删除作业
	 * @param projId
	 * @param projId
	 * @return
	 * @throws Exception
	 */
	public int delete(Long projId,Long jobId) throws Exception{
		pasJobService.delete(projId,jobId);
		log.debug("作业"+jobId+"删除成功");
		return 1;
	}

	public List listResultData(Long projectId,Long jobId) throws Exception {
		List list = pas04ResultService.getInterfaces(projectId,jobId,null,null,null);
		return list;
	}
}
